package com.supreme.threadserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.commonmybatis.entity.primary.MBStorage;
import com.supreme.commonentity.mysql.primary.MBTest;
import com.supreme.threadserver.service.TransactionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "simple")
public class BizThreadController {

    @Resource
    private TransactionService transactionService;

    @GetMapping(value = "tests")
    public AjaxResp testList() {
        final List<MBTest> testList = transactionService.testList();
        return AjaxResp.instance(testList);
    }

    @PostMapping(value = "postRequest")
    public AjaxResp postRequest(@RequestParam Map<String, Integer> bodyData) {
        System.out.println(bodyData);
        return AjaxResp.instance();
    }

    @PostMapping(value = "tests")
    public AjaxResp createTest(@RequestBody MBTest test) {
        final int result = transactionService.createTest(test);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createStorage")
    public AjaxResp createStorage(@RequestBody MBStorage storage) {
        final int result = transactionService.createStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createTestStorage")
    public AjaxResp createTestStorage(@RequestBody MBStorage storage) throws Exception {
        final int result = transactionService.createTestStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createPrivateTestStorage")
    public AjaxResp createPrivateTestStorage(@RequestBody MBStorage storage) {
        final int result = transactionService.createPrivateTestStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createThreadTestStorage")
    public AjaxResp createThreadTestStorage(@RequestBody MBStorage storage) {
        final int result = transactionService.createThreadTestStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createCallableTestStorage")
    public AjaxResp createCallableTestStorage(@RequestBody MBStorage storage) {
        final int result = transactionService.createCallableTestStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createAsyncTestStorage")
    public AjaxResp createAsyncTestStorage(@RequestBody MBStorage storage) {
        final int result = transactionService.createAsyncTestStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createAsyncFutureTestStorage")
    public AjaxResp createAsyncFutureTestStorage(@RequestBody MBStorage storage) {
        final int result = transactionService.createAsyncFutureTestStorage(storage);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "createRandomOrder")
    public AjaxResp createRandomOrder() {
        int result = transactionService.createRandomOrder();
        return AjaxResp.instance(result);
    }

    @GetMapping(value = "tatSyncTest")
    public AjaxResp tatSyncTest(@RequestParam(value = "status", defaultValue = "0") int status) {
        transactionService.tatSyncTest(status);
        return AjaxResp.instance();
    }
}
